import request from '../utils/request'
import type { Announcement } from '../api/announcement'

// 医生信息类型定义
export interface Doctor {
  doctorid: number
  name: string
  age: number
  sex: number  // 1: 男, 0: 女
  email: string
  avatar?: string
  skill: string  // 专业技能
}

// 医生工作时间段类型定义
export interface TimeSlot {
  timelistId: number
  doctorId: number
  weekday: number
  begTime: string
  endTime: string
  maxCapacity: number
  currentCapacity: number
}

// 获取医生列表
export const getDoctorList = (params: {
  page: number
  size: number
  name?: string
  skill?: string
  sex?: number
}) => {
  return request({
    url: '/doctor/list',
    method: 'get',
    params
  })
}

// 获取医生详情
export const getDoctorDetail = (doctorId: number) => {
  return request<Doctor>({
    url: `/doctor/detail/${doctorId}`,
    method: 'get'
  })
}

// 获取医生工作时间表
export const getDoctorSchedule = (doctorId: number) => {
  return request<TimeSlot[]>({
    url: `/timelist/doctor/list`,
    method: 'get',
    params: {
      doctorId
    }
  })
}

// 更新医生信息
export const updateDoctorInfo = (data: {
  doctorid: number
  name: string
  sex: number
  age: number
  email: string
  password: string
  skills: string
}) => {
  return request({
    url: '/doctor/update',
    method: 'put',
    params:data
  })
}

// 设置工作时间
export const setDoctorSchedule = (data: {
  weekday: number
  begTime: string
  endTime: string
  currentCapacity: number
  doctorId: number
}) => {
  return request({
    url: '/timelist/create',
    method: 'post',
    params:data
  })
}

// 删除工作时间
export const deleteDoctorSchedule = (timelistId: number) => {
  return request({
    url: `/timelist/delete`,
    method: 'delete',
    params: {
      timelistId
    }
  })
}

// 获取医生的所有工作时间
export const getDoctorAllSchedule = (doctorId: number) => {
  return request<TimeSlot[]>({
    url: `/timelist/doctor/list`,
    method: 'get',
    params: {
      doctorId
    }
  })
}

// 上传医生头像
export const uploadDoctorAvatar = (doctorId: number, file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: `/doctor/img/${doctorId}`,
    method: 'put',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}
export const deleteAnnouncement = (announcementId: number) => {

  return request({

    url: '/announcement/delete',

    method: 'delete',

    params: { announcementId }

  })

}

// 获取咨询师发布的资讯列表
export const getDoctorAnnouncements = (creatorId: number) => {
  return request<{
    code: string
    msg: string
    data: Announcement[]
  }>({
    url: '/announcement/doctor/list',
    method: 'get',
    params: {
      creatorId
    }
  })
}
